<?php
/**
 * Created by PhpStorm.
 * User: 44766
 * Date: 2018-11-25
 * Time: 18:08
 */

namespace App\Http\Controllers\Api;


use App\Models\Feedback;
use Illuminate\Database\Eloquent\Model;
use Request;

class FeedbackController extends ResourceController
{

    /**
     * @return \Illuminate\Http\JsonResponse
     * @throws \Exception
     */
    public function store()
    {
        $feedback = new Feedback();
        $feedback->fill(Request::all());
        $feedback->save();
        if (Request::get('module_type') == 'position') {
            $count = Feedback::whereModuleType('position')
                ->whereModuleId(Request::get('module_id'))
                ->whereReason(Request::get('reason'))
                ->distinct('member_id')
                ->count();
            if ($count >= 10) {
                $feedback->module->delete();
            }
        }
        return $this->success();
    }

}